/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("InductionFurnacePD",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using Mercury.Entity.DomainModels;
using Mercury.Business.IServices;
using Mercury.Core.Utilities;
using Mercury.Core.Common;
using Mercury.Business.IRepositories;
using Mercury.Core.Enums;
using Mercury.Core.Filters;
using Microsoft.AspNetCore.SignalR;
using Mercury.WebApi.Controllers.Hubs;

namespace Mercury.Business.Controllers
{
    [Route("api/IFPD")]
    public partial class InductionFurnacePDController
    {
        private readonly IInductionFurnacePDService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IInductionFurnacePDRepository _repository;
        private readonly HomePageMessage _message;
        [ActivatorUtilitiesConstructor]
        public InductionFurnacePDController(
            IInductionFurnacePDService service,
            IInductionFurnacePDRepository repository,
            IHttpContextAccessor httpContextAccessor, 
            HomePageMessage message
        )
        : base(service)
        {
            _message = message;
            _service = service;
            _repository = repository;
            _httpContextAccessor = httpContextAccessor;
        }


        [Route("CreateBill/{orderNo}"), HttpGet]
        [ApiActionPermission(ActionPermissionOptions.Ingredient)]
        public async Task<WebResponseContent> GetMaterialsAmount(string orderNo)
        {
            var result = await orderNo.IngredientListCalculation(_repository, createBill: true, sendNoticeAction: _message.SendNoticeAction);
            return new WebResponseContent()
            {
                Status = result.Item1,
                Message = result.Item1 ? "配料成功，请前往配料单查看配料结果！" : result.Item2,
                Data = result.Item3
            };

        }

        [Route("CreateBillResidueFirst/{orderNo}"), HttpGet]
        [ApiActionPermission(ActionPermissionOptions.Ingredient2)]

        public async Task<WebResponseContent> CreateBill(string orderNo)
        {
            var result = await orderNo.IngredientListCalculation(_repository, createBill: true, residueFirst: true, sendNoticeAction: _message.SendNoticeAction);
            return new WebResponseContent()
            {
                Status = result.Item1,
                Message = result.Item1 ? "配料成功，请前往配料单查看配料结果！" : result.Item2,
                Data = result.Item3
            };

        }
    }
}
